<template>
  <div>
    <select v-model.number="num">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="handleIncrement">增加</button>
    <button @click="handleDecrement">减少</button>
    <button @click="handleIncrementIfOdd">奇数增加</button>
    <button @click="handleIncrementAsync">延迟1S增加</button>
  </div>
</template>

<script>
export default {
  name: 'CounterUpdate',
  data () {
    return {
      num: 1
    }
  },
  methods: {
    handleIncrement () {
      // 触发名为increment的mutation调用
      this.$store.commit('increment', this.num)
    },
    handleDecrement () {
      // 触发名为decrement的mutation调用
      this.$store.commit('decrement', this.num)
    },
    handleIncrementIfOdd () {
      // 触发名为incrementIfOdd的action调用
      this.$store.dispatch('incrementIfOdd', this.num)
    },
    handleIncrementAsync () {
      // 触发名为incrementAsync的action调用
      this.$store.dispatch('incrementAsync', this.num)
    },
  }
}
</script>

<style scoped>

</style>
